package observer02;

import observer02.imp.IHanFeiZi;
import observer02.imp.Observable;
import observer02.imp.Observer;

import java.util.ArrayList;

public class HanFeiZi implements Observable, IHanFeiZi {

    /**
     * 存放所有观察者
     */
    private ArrayList<Observer> observerList = new ArrayList<>();

    @Override
    public void haveBreakfast() {
        System.out.println("韩非子：开始吃早饭了。。。");
        this.notifyObserver("韩非子在吃早饭");
    }

    @Override
    public void haveFun() {
        System.out.println("韩非子：开始玩耍。。。");
        this.notifyObserver("韩非子在玩耍");
    }

    @Override
    public void addObserver(Observer observer) {
        this.observerList.add(observer);
    }

    @Override
    public void deleteObserver(Observer observer) {
        this.observerList.remove(observer);
    }

    @Override
    public void notifyObserver(String context) {
        for(Observer observer : this.observerList){
            observer.update(context);
        }
    }
}
